package com.ying.dogying.controller;

import cn.hutool.core.map.MapUtil;
import com.ying.dogying.entity.Const;
import com.ying.dogying.entity.ImUser;
import com.ying.dogying.entity.Response;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping(value = "/im-chat")
public class ImChatController extends BaseController{


    /**
     * 获取我和群的信息
     */
    @GetMapping(value = "/getUserAndGroup")
    public Response getMyInfoAndGroupInfo() {

        // 默认群
        Map<String, Object> imGroup = new HashMap<>();
        imGroup.put("id", Const.IM_GROUP_ID);
        imGroup.put("name", "社区群聊");
        imGroup.put("type", "group");
        imGroup.put("avatar", "http://tp1.sinaimg.cn/5619439268/180/40030060651/1");
        imGroup.put("members", 3);
        // 获取我的信息
        ImUser imUser = imChatService.getCurrentUser();
        return new Response().success(MapUtil.builder().put("imGroup", imGroup).put("imUser", imUser).map());
    }

    /**
     * 获取群历史消息
     */
    @GetMapping(value = "/getGroupHistoryMessage")
    public Response getGroupHistoryMessage() {
        List<Object> messages = imChatService.getGroupHistoryMessage(20);
        return new Response().success(messages);
    }

    /**
     * 获取成员
     */
    @GetMapping(value = "/getMembers")
    public Response getMembers() {
        return new Response().success();
    }
}
